package org.dandsoft.blackbox.laboratory.tools.view;

import org.dandsoft.blackbox.laboratory.tools.JCRMonitorStorage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: dvilyuzhanin
 * Date: 29.03.2009 23:35:45
 */
public class EnviromentStateForm extends JFrame {

    private EnviromentStateView enviromentView;


    public EnviromentStateForm(JCRMonitorStorage monitor) throws HeadlessException {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        enviromentView = new EnviromentStateView();
        enviromentView.setStorage(monitor);
        setLayout(new BorderLayout());
        add(enviromentView, BorderLayout.CENTER);
        setSize(700, 700);
        showToolbar();
        setVisible(true);
    }

    private void showToolbar() {
        JPanel toolbar = new JPanel();

        JButton refresh = new JButton("Refresh");
        refresh.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                enviromentView.updateImage();
            }
        });

        JButton zoomUp = new JButton("-");
        zoomUp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                enviromentView.zoomUp();
                enviromentView.repaint();
            }
        });

        JButton zoomDown = new JButton("+");
        zoomDown.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                enviromentView.zoomDown();
                enviromentView.repaint();
            }
        });

        toolbar.setLayout(new FlowLayout());

        toolbar.add(refresh);
        toolbar.add(zoomDown);
        toolbar.add(zoomUp);

        add(toolbar, BorderLayout.NORTH);

    }

    public static void main(String[] args) {
        File file = new File("e:/lighter");
        if (!file.exists()) {
            throw new RuntimeException("repository not found");
        }
        JCRMonitorStorage monitor = JCRMonitorStorage.createRepository(file.getAbsolutePath());
        new EnviromentStateForm(monitor);
    }
}
